package Fragment

import adapter.IdCardAdapter
import adapter.PersonAdapterUtil
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.hospitalmanagementapp.*
import com.example.hospitalmanagementapp.databinding.FragmentPersonBinding
import kotlinx.android.synthetic.main.fragment_person.*

class PersonFragment : Fragment() {
private lateinit var personBinding: FragmentPersonBinding
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        personBinding= DataBindingUtil.inflate(
            inflater, R.layout.fragment_person, container, false
        )
        return  personBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()

    }

    private fun initView() {
        id_card_recycler.layoutManager=LinearLayoutManager(requireActivity())
        var dataList: MutableList<IdModel> = mutableListOf(
            IdModel(
                "王凡",
                "612326********591X",
                "3"
            )
        )
        id_card_recycler.setOnClickListener {
           startActivity(Intent(context,PeopleListActivity::class.java))
        }
        var adapter = IdCardAdapter(requireActivity())
        adapter.dataList = dataList
        id_card_recycler.adapter = adapter

        payment_service_item.layoutManager = GridLayoutManager(requireActivity(),4)
        var datalist01: MutableList<PayModel> = mutableListOf(
           PayModel(
                R.mipmap.pay_service,
                "取号服务"
            )
        )
        var adapter01 = PersonAdapterUtil(requireActivity())
        adapter01.dataList = datalist01
        payment_service_item.setOnClickListener {
            object:View.OnClickListener{
                override fun onClick(v: View?) {

                }

            }
        }
        payment_service_item.adapter = adapter01

        integrated_query_item.layoutManager = GridLayoutManager(requireActivity(),4)
        var datalist02: MutableList<PayModel> = mutableListOf(
            PayModel(
                R.mipmap.inspection_report,
                "检验报告单"
            ), PayModel(
                R.mipmap.examination_report,
                "检查报告单"
            ), PayModel(
                R.mipmap.outpatient,
                "门诊花费"
            ), PayModel(
                R.mipmap.daily_list,
                "每日清单"
            )

        )
        var adapter02 =PersonAdapterUtil(requireActivity())
        adapter02.setListener {
            when(it){
                0->startActivity(Intent(requireActivity(),ReportActivity::class.java))
                1-> startActivity(Intent(requireActivity(),ReportActivity::class.java))
            }
        }
        adapter02.dataList = datalist02
        integrated_query_item.adapter = adapter02


        handy_service_for_the_public_item.layoutManager = GridLayoutManager(requireActivity(),4)
        var datalist03:MutableList<PayModel> = mutableListOf(
           PayModel(
                R.mipmap.smart_waitting,
                "智能候诊"
            ), PayModel(
                R.mipmap.dining_service,
                "就餐服务"
            ), PayModel(
                R.mipmap.dining_service,
                "就餐服务（测试）"
            ), PayModel(
                R.mipmap.pharmaceutical_cube,
                "药立方"
            )
        )
        var adapter03 = PersonAdapterUtil(requireActivity())
        adapter03.dataList = datalist03

        handy_service_for_the_public_item.adapter = adapter03

        loadAdd()
    }
    fun loadAdd() {
        add_massage.setOnClickListener {
            startActivity(Intent(requireContext(),IncreaseActivity::class.java))
        }
    }
}